<?php

	# PID		NEW->	00397	EDIT-> 00398

	require_once($GLOBALS['BIB'].'Pr_db/pr_historics.mex');
	$RegID = 0;
	if (!isset($_POST['smv_DateEnd'])) {$_POST['smv_DateEnd'] = 'null';} else { $_POST['smv_DateEnd'] = "'{$_POST['smv_DateEnd']}'"; }
	
	if ($_POST['tsv_ID'] == 0) {
		if ($_POST['tsv_Type'] == 1) {
		$PID = 397;
		$PNAME = 'STAFFMEMBER_OFF';
		} else {
		$PID = 398;
		$PNAME = 'STAFFMEMBER_OOF';
		}
		if($GLOBALS['MYT']->db_query("INSERT INTO systemoffice.timeclock_staffoff (tsv_Flag, tsv_Member, tsv_Domain, tsv_DateStart, tsv_DateEnd, tsv_Process, tsv_Observations, tsv_User)
		VALUES (1,{$_POST['MemberID']},'{$_POST['MemberDomain']}','{$_POST['tsv_DateStart']}','{$_POST['tsv_DateEnd']}',{$PID},'{$_POST['tsv_Observations']}',{$_SESSION[$SESSID]})")==true) {
			$GetRecord = $GLOBALS['MYT']->db_array("SELECT tsv_ID FROM systemoffice.timeclock_staffoff WHERE tsv_User = {$_SESSION[$SESSID]} ORDER BY tsv_ID DESC LIMIT 0,1");
			systemchange_hs($PNAME,$GetRecord[1]['tsv_ID']);	
			$RegID = $GetRecord[1]['tsv_ID'];
			$TaskTime = $_POST['tsv_DateStart'];
		echo '<script charset="utf-8" type="text/javascript">document.staffmv.tsv_ID.value='.$GetRecord[1]['tsv_ID'].';</script>';			
		}
	} else {
		if ($_POST['tsv_Type'] == 1) {
		$PID = 401;
		$PNAME = 'STAFF_EDITOFF';
		} else {
		$PID = 402;
		$PNAME = 'STAFF_EDITOOF';
		}
		if($GLOBALS['MYT']->db_query("UPDATE systemoffice.timeclock_staffoff
			SET 
				tsv_Flag = {$_POST['tsv_Flag']}, 
				tsv_Process = {$PID},
				tsv_Observations = '{$_POST['tsv_Observations']}',
				tsv_User = {$_SESSION[$SESSID]}
			WHERE tsv_ID = {$_POST['tsv_ID']}")==true) {
			systemchange_hs($PNAME,$_POST['tsv_ID']);		
		}
	}
	echo '<div class="Confirm">Guardado.</div>';
	if ($RegID != 0) {
	include($GLOBALS['BIB'].'Pr_db/prc_modules/rh_comunication.php');
	}